package com.woniuxy.config.delay;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Todo: 延迟队列
 * @DateTime: 25/09/02/星期二 10:34
 * @Component: 成都蜗牛学苑
 **/
@Configuration
public class DelayMQConfig {
    @Bean
    public Queue delayQueue(){
        return new Queue("delay_queue");
    }
    @Bean
    public CustomExchange customDelayExchange(){
        Map<String, Object> args = new HashMap<>();
        //延迟交换机的 类型， 直连交换机（route模式） 广播  主题
        args.put("x-delayed-type","direct");
        return new CustomExchange("delay_exchange","x-delayed-message",
                true,false,args);
    }
    @Bean
    public Binding bindingDelayQueue(){
        return BindingBuilder.bind(delayQueue())
                .to(customDelayExchange())
                .with("delay")
                .noargs();
    }
}
